package com.hitqz.robot.biz.flow.component.common;

import com.hitqz.robot.biz.flow.domain.dto.TestContextDto;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author xupkun
 * @date 2024/1/27
 */
@LiteflowComponent(value = "testTwoComponent",name = "[通用组件]测试二")
@Slf4j
public class TestTwoComponent extends NodeComponent {



    @Override
    public void process() throws Exception {
        TestContextDto contextDto = this.getRequestData();
        Integer subChain = this.getSubChainReqData();
        log.info("[two]contextDto:{}",contextDto);
        log.info("[two]subChain id:{}",subChain);
        Map<String, AtomicInteger> indexMap = contextDto.getIndex();
        if (!indexMap.containsKey(this.getName())){
            indexMap.putIfAbsent(this.getName(),new AtomicInteger(0));
        }
        AtomicInteger atomicInteger = indexMap.get(this.getName());
        int andIncrement = atomicInteger.getAndIncrement();
        Integer id = contextDto.getIds().get(Math.min(andIncrement,contextDto.getIds().size()-1));
        log.info("[two]index:{},id:{}",andIncrement,id);
    }



}
